<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Installation in MacOS</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../df/d65/tutorial_table_of_content_introduction.html">Introduction to OpenCV</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Installation in MacOS </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../d7/dbd/tutorial_android_ocl_intro.html">Use OpenCL in Android camera preview based CV application</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../d0/d76/tutorial_arm_crosscompile_with_cmake.html">Cross compilation for ARM based Linux systems</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left"><code>@sajarindider</code> </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 3.4 </td></tr>
</table>
<p>The following steps have been tested for MacOSX (Mavericks) but should work with other versions as well.</p>
<h2>Required Packages </h2>
<ul>
<li>CMake 3.9 or higher</li>
<li>Git</li>
<li>Python 2.7 or later and Numpy 1.5 or later</li>
</ul>
<p>This tutorial will assume you have <a href="https://docs.python.org/3/using/mac.html">Python</a>, <a href="https://docs.scipy.org/doc/numpy-1.10.1/user/install.html">Numpy</a> and <a href="https://www.atlassian.com/git/tutorials/install-git">Git</a> installed on your machine.</p>
<dl class="section note"><dt>Note</dt><dd>OSX comes with Python 2.7 by default, you will need to install Python 3.8 if you want to use it specifically.</dd>
<dd>
If you XCode and XCode Command Line-Tools installed, you already have git installed on your machine.</dd></dl>
<h2>Installing CMake </h2>
<ol type="1">
<li>Find the version for your system and download CMake from their release's <a href="https://cmake.org/download/">page</a></li>
<li>Install the dmg package and launch it from Applications. That will give you the UI app of CMake</li>
<li>From the CMake app window, choose menu Tools &ndash;&gt; How to Install For Command Line Use. Then, follow the instructions from the pop-up there.</li>
<li>Install folder will be /usr/bin/ by default, submit it by choosing Install command line links.</li>
<li>Test that it works by running <div class="fragment"><div class="line">cmake --version</div></div><!-- fragment --></li>
</ol>
<dl class="section note"><dt>Note</dt><dd>You can use <a href="https://brew.sh/">Homebrew</a> to install CMake with<div class="fragment"><div class="line">brew install cmake </div></div><!-- fragment --></dd></dl>
<h2>Getting OpenCV Source Code </h2>
<p>You can use the latest stable OpenCV version or you can grab the latest snapshot from our <a href="https://github.com/opencv/opencv.git">Git repository</a>.</p>
<h3>Getting the Latest Stable OpenCV Version</h3>
<ul>
<li>Go to our <a href="http://opencv.org/releases.html">downloads page</a>.</li>
<li>Download the source archive and unpack it.</li>
</ul>
<h3>Getting the Cutting-edge OpenCV from the Git Repository</h3>
<p>Launch Git client and clone <a href="http://github.com/opencv/opencv">OpenCV repository</a>. If you need modules from <a href="http://github.com/opencv/opencv_contrib">OpenCV contrib repository</a> then clone it as well.</p>
<p>For example </p><div class="fragment"><div class="line">cd ~/&lt;my_working_directory&gt;</div><div class="line">git clone https://github.com/opencv/opencv.git</div><div class="line">git clone https://github.com/opencv/opencv_contrib.git</div></div><!-- fragment --> <h2>Building OpenCV from Source Using CMake </h2>
<ol type="1">
<li><p class="startli">Create a temporary directory, which we denote as <code>build_opencv</code>, where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there.</p>
<p class="startli">For example </p><div class="fragment"><div class="line">mkdir build_opencv</div><div class="line">cd build_opencv</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>It is good practice to keep clean your source code directories. Create build directory outside of source tree.</dd></dl>
</li>
<li><p class="startli">Configuring. Run <code>cmake [&lt;some optional parameters&gt;] &lt;path to the OpenCV source directory&gt;</code></p>
<p class="startli">For example </p><div class="fragment"><div class="line">cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ../opencv</div></div><!-- fragment --><p class="startli">or cmake-gui</p><ul>
<li>set the OpenCV source code path to, e.g. <code>/home/user/opencv</code></li>
<li>set the binary build path to your CMake build directory, e.g. <code>/home/user/build_opencv</code></li>
<li>set optional parameters</li>
<li>run: "Configure"</li>
<li>run: "Generate"</li>
</ul>
</li>
<li>Description of some parameters<ul>
<li>build type: <code>CMAKE_BUILD_TYPE=Release</code> (or <code>Debug</code>)</li>
<li>to build with modules from opencv_contrib set <code>OPENCV_EXTRA_MODULES_PATH</code> to <code>&lt;path to opencv_contrib&gt;/modules</code></li>
<li>set <code>BUILD_DOCS=ON</code> for building documents (doxygen is required)</li>
<li>set <code>BUILD_EXAMPLES=ON</code> to build all examples</li>
</ul>
</li>
<li>[optional] Building python. Set the following python parameters:<ul>
<li><code>PYTHON3_EXECUTABLE = &lt;path to python&gt;</code></li>
<li><code>PYTHON3_INCLUDE_DIR = /usr/include/python&lt;version&gt;</code></li>
<li><code>PYTHON3_NUMPY_INCLUDE_DIRS = /usr/lib/python&lt;version&gt;/dist-packages/numpy/core/include/</code> <dl class="section note"><dt>Note</dt><dd>To specify Python2 versions, you can replace <code>PYTHON3_</code> with <code>PYTHON2_</code> in the above parameters.</dd></dl>
</li>
</ul>
</li>
<li><p class="startli">Build. From build directory execute <em>make</em>, it is recommended to do this in several threads</p>
<p class="startli">For example </p><div class="fragment"><div class="line">make -j7 # runs 7 jobs in parallel</div></div><!-- fragment --></li>
<li>To use OpenCV in your CMake-based projects through <code>find_package(OpenCV)</code> specify <code>OpenCV_DIR=&lt;path_to_build_or_install_directory&gt;</code> variable.</li>
</ol>
<dl class="section note"><dt>Note</dt><dd>You can also use a package manager like <a href="https://brew.sh/">Homebrew</a> or <a href="https://pip.pypa.io/en/stable/">pip</a> to install releases of OpenCV only (Not the cutting edge). </dd></dl>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:36 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
